/**
 * Collection Task API Service
 * 采集任务管理API服务 (FR-006 ~ FR-009a)
 */

import { get, post } from './client'
import type {
  ApiResponse,
  PageResponse,
  CollectionTask,
  CollectionTaskCreateRequest,
} from '../models/types'

export const listCollectionTasks = async (params: any): Promise<ApiResponse<PageResponse<CollectionTask>>> => {
  return get<PageResponse<CollectionTask>>('/collection-tasks', { params })
}

export const getCollectionTask = async (id: number): Promise<ApiResponse<CollectionTask>> => {
  return get<CollectionTask>(`/collection-tasks/${id}`)
}

export const createCollectionTask = async (data: CollectionTaskCreateRequest): Promise<ApiResponse<CollectionTask>> => {
  return post<CollectionTask>('/collection-tasks', data)
}

export const startCollectionTask = async (id: number): Promise<ApiResponse<CollectionTask>> => {
  return post<CollectionTask>(`/collection-tasks/${id}/start`, {})
}

export const cancelCollectionTask = async (id: number): Promise<ApiResponse<void>> => {
  return post<void>(`/collection-tasks/${id}/cancel`, {})
}

export const retryFailedTables = async (id: number): Promise<ApiResponse<CollectionTask>> => {
  return post<CollectionTask>(`/collection-tasks/${id}/retry-failed`, {})
}
